<template>
	<view>
		<view class="login-form">
			<u-input v-model="oldPwd" placeholder="请输入旧密码" type="password"/>
			<u-input v-model="newPwd" placeholder="请输入新密码" type="password"/>
			<u-input v-model="newPwdConfirm" placeholder="请确认新密码" type="password"/>
			<u-button type="primary" plain @click="updatePassword">修改</u-button>
		</view>
	</view>
</template>

<script>
import userApi from "@/api/client/userApi";

export default {
	data() {
		return {
			oldPwd: '',
			newPwd: '',
			newPwdConfirm: ''
		};
	},
	methods: {
		updatePassword() {
			if (this.newPwd !== this.newPwdConfirm) {
				uni.showToast({
					title: "两次输入的密码不一致!",
					icon: "none"
				});
				return;
			}
			
			userApi.updatePassword(this.oldPwd, this.newPwd).then(_ => {
				uni.navigateTo({url: "/pages/login/login"})
			})
		}
	},
}
</script>

<style lang="scss">

.login-form {
	margin-top: 20%;
	margin-left: 120rpx;
	margin-right: 120rpx;
	padding: 36rpx;
	display: flex;
	flex-direction: column;
	gap: 36rpx
}

</style>
